//package co.fitstart.market.scheduler;
//
//import java.util.Date;
//import java.util.List;
//
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.beans.factory.annotation.Qualifier;
//import org.springframework.scheduling.annotation.Scheduled;
//import org.springframework.stereotype.Component;
//
//import com.demo2do.core.utils.JsonUtils;
//import com.demo2do.core.web.support.HttpResult;
//
//import co.fitstart.entity.order.Order;
//import co.fitstart.entity.site.Site;
//import co.fitstart.market.handler.WxcClientOrderHandler;
//import co.fitstart.market.service.DataService;
//import co.fitstart.market.service.OrderServie;
//
///**
// * 
// * @author mohanlan
// *
// */
//@Component
//public class WxcOrderScheduler {
//    
//    private static final Logger logger = LoggerFactory.getLogger(WxcOrderScheduler.class);
//    
//    private static final Long siteId = 6L;
//    
//    @Autowired
//    @Qualifier("dataService")
//    private DataService<Site> siteService;
//    
//    @Autowired
//    private OrderServie orderServie;
//    
//    @Autowired
//    private WxcClientOrderHandler wxcClientOrderHandler;
//    
//    /**
//     * 
//     */
//    @Scheduled(cron = "0 40 23 * * *")
//    public void scanWxcOrder() {
//        
//        Date now = new Date();
//        Date yesterday = org.apache.commons.lang3.time.DateUtils.addDays(now, -1);
//        
//        logger.info("start running WxcOrderScheduler#scanWxcOrder at {}", now);
//        
//        Site site = siteService.load(Site.class, WxcOrderScheduler.siteId);
//        List<Order> orders = orderServie.listUnPostOrder(now, yesterday, site);
//        
//        for(Order order : orders) {
//            
//            HttpResult httpResult = wxcClientOrderHandler.create(order);
//            logger.info("upload order [{}], get result[{}]", order.getId(), JsonUtils.toJsonString(httpResult));
//            
//            if(httpResult.isValid()) {
//                orderServie.uploadedWxc(order);
//            }
//        }
//        
//    }
//    
//}
